﻿using System;
namespace Producers.Etoimik.Xtee.Riik.Ee.Producer.Etoimik {
    
    
    [global::Xtee.Core.Attributes.XmlTypeAttribute(Name="Olek", Namespace="http://producers.etoimik.xtee.riik.ee/producer/etoimik", Target=typeof(Olek))]
    public class OlekSerializer : global::Xtee.Core.Types.AbstractXteeSerializable {
        
        protected IOlek clazz;
        
        public OlekSerializer(IOlek clazz) {
            this.clazz = clazz;
        }
        
        public override void WriteXml(global::Xtee.Core.IXteeXmlWriter Writer) {
            base.WriteXml(Writer);
            if (clazz.OlekKL!=null) {
                Writer.WriteStartElement("OlekKL");
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "long");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdLong(((long)(clazz.OlekKL))).ToString());
                Writer.WriteEndElement();
            }
            if (clazz.OlekuMargeKL!=null) {
                Writer.WriteStartElement("OlekuMargeKL");
                Writer.WriteTypeAttribute("http://schemas.xmlsoap.org/soap/encoding/", "Array");
                Writer.WriteArrayTypeAttribute("long", "http://www.w3.org/2001/XMLSchema", clazz.OlekuMargeKL.Count);
                for (int x = 0; ((clazz.OlekuMargeKL != null) 
                            && (x < clazz.OlekuMargeKL.Count)); x = (x + 1)) {
                    if (clazz.OlekuMargeKL[x]!=null) {
                        Writer.WriteStartElement("item");
                        Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "long");
                        Writer.WriteString(new global::Xtee.Core.Schema.XsdLong(((long)(clazz.OlekuMargeKL[x]))).ToString());
                        Writer.WriteEndElement();
                    }
                }
                Writer.WriteEndElement();
            }
            if (clazz.Selgitus!=null) {
                Writer.WriteStartElement("Selgitus");
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.Selgitus))).ToString());
                Writer.WriteEndElement();
            }
            if (clazz.ToiminguNR!=null) {
                Writer.WriteStartElement("ToiminguNR");
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.ToiminguNR))).ToString());
                Writer.WriteEndElement();
            }
            if (clazz.ToiminguObjektID!=null) {
                Writer.WriteStartElement("ToiminguObjektID");
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "long");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdLong(((long)(clazz.ToiminguObjektID))).ToString());
                Writer.WriteEndElement();
            }
            if (clazz.AlgusKP!=null) {
                Writer.WriteStartElement("AlgusKP");
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "dateTime");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdDateTime(((System.DateTime)(clazz.AlgusKP))).ToString());
                Writer.WriteEndElement();
            }
            if (clazz.LoppKP!=null) {
                Writer.WriteStartElement("LoppKP");
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "dateTime");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdDateTime(((System.DateTime)(clazz.LoppKP))).ToString());
                Writer.WriteEndElement();
            }
            if (clazz.ToiminguTegijaAsutusCSV!=null) {
                Writer.WriteStartElement("ToiminguTegijaAsutusCSV");
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.ToiminguTegijaAsutusCSV))).ToString());
                Writer.WriteEndElement();
            }
            if (clazz.ToiminguTegijaCSV!=null) {
                Writer.WriteStartElement("ToiminguTegijaCSV");
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.ToiminguTegijaCSV))).ToString());
                Writer.WriteEndElement();
            }
        }
        
        public override void ReadXml(global::Xtee.Core.IXteeXmlReader Reader) {
            base.ReadXml(Reader);
            if (Reader.LocalName=="OlekKL") {
                if ((Reader.IsElementNil() == false)) {
                    clazz.OlekKL = new global::Xtee.Core.Schema.XsdLong(Reader.ReadElementString("OlekKL")).Value;
                }
                else {
                    Reader.Skip();
                }
            }
            if (Reader.LocalName=="OlekuMargeKL") {
                if ((Reader.IsElementNil() == false)) {
                    clazz.OlekuMargeKL = new System.Collections.Generic.List<System.Int64?>();
                    if ((Reader.IsEmptyElement == false)) {
                        Reader.ReadStartElement("OlekuMargeKL");
                        for (; ((Reader.NodeType != System.Xml.XmlNodeType.EndElement) 
                                    && (Reader.LocalName == "item")); ) {
                            if (Reader.IsElementNil()) {
                                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>>Olek>OlekuMargeKL>item");
                            }
                            clazz.OlekuMargeKL.Add(new global::Xtee.Core.Schema.XsdLong(Reader.ReadElementString("item")).Value);
                        }
                        Reader.ReadEndElement();
                    }
                    else {
                        Reader.Skip();
                    }
                }
                else {
                    Reader.Skip();
                }
            }
            if (Reader.LocalName=="Selgitus") {
                if ((Reader.IsElementNil() == false)) {
                    clazz.Selgitus = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("Selgitus")).Value;
                }
                else {
                    Reader.Skip();
                }
            }
            if (Reader.LocalName=="ToiminguNR") {
                if ((Reader.IsElementNil() == false)) {
                    clazz.ToiminguNR = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("ToiminguNR")).Value;
                }
                else {
                    Reader.Skip();
                }
            }
            if (Reader.LocalName=="ToiminguObjektID") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>Olek>ToiminguObjektID");
                }
                clazz.ToiminguObjektID = new global::Xtee.Core.Schema.XsdLong(Reader.ReadElementString("ToiminguObjektID")).Value;
            }
            if (Reader.LocalName=="AlgusKP") {
                if ((Reader.IsElementNil() == false)) {
                    clazz.AlgusKP = new global::Xtee.Core.Schema.XsdDateTime(Reader.ReadElementString("AlgusKP")).Value;
                }
                else {
                    Reader.Skip();
                }
            }
            if (Reader.LocalName=="LoppKP") {
                if ((Reader.IsElementNil() == false)) {
                    clazz.LoppKP = new global::Xtee.Core.Schema.XsdDateTime(Reader.ReadElementString("LoppKP")).Value;
                }
                else {
                    Reader.Skip();
                }
            }
            if (Reader.LocalName=="ToiminguTegijaAsutusCSV") {
                if ((Reader.IsElementNil() == false)) {
                    clazz.ToiminguTegijaAsutusCSV = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("ToiminguTegijaAsutusCSV")).Value;
                }
                else {
                    Reader.Skip();
                }
            }
            if (Reader.LocalName=="ToiminguTegijaCSV") {
                if ((Reader.IsElementNil() == false)) {
                    clazz.ToiminguTegijaCSV = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("ToiminguTegijaCSV")).Value;
                }
                else {
                    Reader.Skip();
                }
            }
        }
    }
}
